//
//  TTBasicView.swift
//  WeiBo
//
//  Created by 涂永江 on 2017/6/5.
//  Copyright © 2017年 涂永江. All rights reserved.
//

import UIKit
import SnapKit
class TTBasicView: UIView {

    var closore:(()->())?
   
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //设置底部选择图片

    
    private lazy var boasstomImage = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
//    //覆盖图片
    private lazy var mindImage = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
//    //上边的图片
//
     private lazy var topImage = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    
    private lazy var regsiter:UIButton = {
    
        let button = UIButton()
        button.addTarget(self, action: #selector(zhuce), for: .touchUpInside)
        button.setTitle("注册", for: .normal)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        var uimage = UIImage(named: "common_button_white_disable")
        //切图
        uimage = uimage?.stretchableImage(withLeftCapWidth: 5, topCapHeight: 5)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        
        button.adjustsImageWhenHighlighted = false
        
        button.setBackgroundImage(uimage, for: .normal)

        return button
    
    }()
    
    private lazy var login:UIButton = {
        
        let button = UIButton()
        button.addTarget(self, action: #selector(denglv), for: .touchUpInside)

        button.setTitle("登录", for: .normal)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        var uimage = UIImage(named: "common_button_white_disable")
        //切图
        uimage = uimage?.stretchableImage(withLeftCapWidth: 5, topCapHeight: 5)
 
        button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        
        button.adjustsImageWhenHighlighted = false
        
        button.setBackgroundImage(uimage, for: .normal)
        return button
        
    }()
    
    func zhuce()
    {
    
    print("注册")
        closore?()
        
    }
    
    func denglv()
    {
    print("登录")
    closore?()
    }
    
    private lazy var descLabel:UILabel = {
    
        let label = UILabel()
        
        label.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        
        label.font = UIFont.systemFont(ofSize: 13)
        
        label.textAlignment = .center
        
        label.textColor = UIColor.darkGray
        
        label.numberOfLines = 0
        
        return label
    
    }()
    
    
    //设置不同的页面的login
    func setOther(isfa:Bool,descu:String?,imageName:String?){
    
        if isfa
        {
            setAnimation()
        }else{
            
            topImage.image = UIImage(named:imageName!)
            descLabel.text = descu!
            boasstomImage.isHidden = true
            
        }
        
    
    }
    
    func setAnimation()
    {
    
    let basicAnimation = CABasicAnimation(keyPath: "transform.rotation")
        basicAnimation.toValue = 2 * Double.pi
    
        basicAnimation.duration = 10
        
        basicAnimation.repeatCount = MAXFLOAT
        //切换到其他界面不关闭动画
        basicAnimation.isRemovedOnCompletion = false
        boasstomImage.layer.add(basicAnimation, forKey: "kk")
    }
    
    //设置控件
   private func setUI()
    {
       self.backgroundColor = UIColor(white: 237 / 255, alpha: 1)
        addSubview(boasstomImage)
        addSubview(mindImage)
        addSubview(topImage)
        addSubview(descLabel)
        addSubview(regsiter)
        addSubview(login)
        
        boasstomImage.snp.makeConstraints { (make) in
            make.center.equalTo(self)
        }
        
        mindImage.snp.makeConstraints { (make) in
            make.center.equalTo(boasstomImage)
        }
        topImage.snp.makeConstraints { (make) in
            make.center.equalTo(mindImage)
        }
        descLabel.snp.makeConstraints { (make) in
            make.top.equalTo(topImage.snp.bottom)
            make.centerX.equalTo(topImage)
            make.size.equalTo(CGSize(width: 220, height: 35))
        }
        regsiter.snp.makeConstraints { (make) in
            make.top.equalTo(descLabel.snp.bottom)
            make.leading.equalTo(descLabel)
            make.width.equalTo(50)
        }
        login.snp.makeConstraints { (make) in
            make.top.equalTo(descLabel.snp.bottom)
            make.trailing.equalTo(descLabel)
            make.width.equalTo(50)
        }
    
    }
    
    
}
